package com.itheima.homework.Demo2;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

public class Demo2 {
    public static void main(String[] args) {

        // 定义Set集合
        Set<String> set = new HashSet<>();
        // 获取字符数组
        char[] chs = getCharArray();

        Random r = new Random();


        while (set.size() < 5 ){
            StringBuilder sb = new StringBuilder();
            // 生成一个验证码
            for (int i = 0; i < 4; i++) {
                int index = r.nextInt(chs.length);
                sb.append(chs[index]);
            }
            set.add(sb.toString());
        }

        // 遍历set集合
        for (String s : set) {
            System.out.println(s);
        }

    }


    public static char[] getCharArray() {
        char[] chs = new char[62];

        int count = 0;

        for (char c = 'a'; c <= 'z'; c++) {
            chs[count++] = c;
        }

        for (char c = 'A'; c <= 'Z'; c++) {
            chs[count++] = c;
        }

        for (char c = '0'; c <= '9'; c++) {
            chs[count++] = c;
        }

        return chs;
    }
}
